package com.encryption.util;

import com.encryption.service.ca.util.CryptoUtil;

public class TestUseUtil {
	
	public static boolean isTest(){
		String code = ConfigProperties.getProperty(ConfigPropertyContanst.USER_CODE);
		String value = ConfigProperties.getProperty(ConfigPropertyContanst.USER_VALUE);
		if(code == null || "".equals(code) || value == null || "".equals(value)){
			return false;
		}
		
		String mac = AuthUtil.getMacOnWindow();
		String md5Mac = CryptoUtil.md5(mac);
		long curTime = System.currentTimeMillis();
		if(code.equals(ConfigPropertyContanst.USER_DEFAULT) && value.equals(ConfigPropertyContanst.USER_DEFAULT)){
			ConfigProperties.setProperty(ConfigPropertyContanst.USER_CODE, md5Mac);
			ConfigProperties.setProperty(ConfigPropertyContanst.USER_VALUE, curTime + "");
		}else if(md5Mac.equals(code)){
			long time = Long.parseLong(value);
			if(curTime - time >= 30L * 24 * 60 * 60 * 1000){
				return false;
			}
		}else{
			return false;
		}
		
		return true;
	}
	
	public static int getTestDate(){
		String value = ConfigProperties.getProperty(ConfigPropertyContanst.USER_VALUE);
		long time = Long.parseLong(value);
		long curTime = System.currentTimeMillis();
		if(curTime - time >= 30L * 24 * 60 * 60 * 1000){
			
		}
		
		return 0;
	}
}
